package com.xx.executor.controller;

import com.xx.common.pojo.XxlJobInfo;
import com.xx.common.api.XxlJobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * index controller
 *
 * @author xuxueli 2015-12-19 16:13:16
 */
@RestController
@RequestMapping("/jobInfo")
@Slf4j
@Api(tags = "调度任务-feign")
public class JobInfoController {

    @Resource
    private XxlJobService xxlJobService;


    /**
     * 添加调度任务
     *
     * @param jobInfo 调度任务
     * @return 结果
     * @throws Exception 错误信息
     */
    @PostMapping("/addJob")
    @ApiOperation(value = "添加调度任务-feign (hxy)")
    public Boolean addJob(@RequestBody XxlJobInfo jobInfo) throws Exception {
        return xxlJobService.add(jobInfo);
    }

    /**
     * 根据执行器任务handler修改任务
     *
     * @param jobInfo 修改调度任务
     * @return 结果
     * @throws Exception 错误信息
     */
    @PostMapping("/updateJob")
    @ApiOperation(value = "根据执行器任务handler修改任务-feign (hxy)")
    public Boolean updateJob(@RequestBody XxlJobInfo jobInfo) throws Exception {
        return xxlJobService.update(jobInfo);
    }

    /**
     * 根据执行器任务handler移除调度任务
     *
     * @param executorHandler 执行器任务handler
     * @return 结果
     * @throws Exception 错误信息
     */
    @PostMapping("/removeJob")
    @ApiOperation(value = "根据执行器任务handler移除调度任务-feign (hxy)")
    public Boolean removeJob(@RequestBody String executorHandler) throws Exception {
        return xxlJobService.remove(executorHandler);
    }

    /**
     * 根据执行器任务handler开启调度任务
     *
     * @param executorHandler 执行器任务handler
     * @return 结果
     * @throws Exception 错误信息
     */
    @PostMapping("/stop")
    @ApiOperation(value = "根据执行器任务handler暂停调度任务-feign (hxy)")
    public Boolean stop(@RequestBody String executorHandler) throws Exception {
        return xxlJobService.stop(executorHandler);
    }

    /**
     * 根据执行器任务handler开启调度任务
     *
     * @param executorHandler 执行器任务handler
     * @return 结果
     * @throws Exception 错误信息
     */
    @PostMapping("/start")
    @ApiOperation(value = "根据执行器任务handler开启调度任务-feign (hxy)")
    public Boolean start(@RequestBody String executorHandler) throws Exception {
        return xxlJobService.start(executorHandler);
    }


}
